package xiangya.bysj.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import xiangya.bysj.entity.Admin;
import xiangya.bysj.mapper.interf.AdminMapper;
import xiangya.bysj.service.interf.AdminServiceInterface;

/**
 * 操作管理员的业务实现类
 * @author Mr.zhang
 *
 */
@Service("adminService")
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class) // 注明需要回滚
public class AdminServiceImpl implements AdminServiceInterface {

	@Resource(name="adminMapper")
	private AdminMapper adminMapper;
	
	@Override
	public void save(Admin obj) throws Exception {
		adminMapper.save(obj);
	}

	@Override
	public void update(Admin obj) throws Exception {
		adminMapper.update(obj);
	}

	@Override
	public void delete(int objId) throws Exception {
		adminMapper.delete(objId);
	}

	@Override
	public Admin login(String adminCount, String password) throws Exception {
		Admin admin = adminMapper.selectByCodeOrPhone(adminCount);
		if(admin == null || !admin.getAdminPass().equals(password)){
			admin = null;
		}
		return admin;
	}

	@Override
	public List<Admin> getSome(int currentPage, int pageNum) throws Exception {
		int from = currentPage*(pageNum - 1);
		List<Admin> list = adminMapper.selectByPage(from, pageNum);
		return list;
	}

}
